import React from 'react'
import { Col, Row, Statistic } from 'antd';
import {useEffect,useState} from "react"
import {Navigate, useNavigate} from "react-router-dom"
import Islogin from '../utils/islogin';
const { Countdown } = Statistic;

const deadline = Date.now() + 1000 * 10; // Moment is also OK
function Home() {
    const navgitate = useNavigate()
    const [ num,setNum] = useState(5)
    useEffect(()=>{
        let timmer = setInterval(()=>{
                setNum((num)=>num - 1) 

            console.log(num);
          
        },1000)
        setTimeout(()=>{
            navgitate("/login")
        },4900)
        return ()=>{ // return 得这个函数就是组件销毁的生命周期
           clearInterval(timmer) // 合理释放内存
        }
    },[])
    useEffect(()=>{
        if (num < 3) {
                console.log("我执行了");
        }
    },[num])
    const onFinish = () => { // 结束的时候需要做的事情
        console.log('finished!');
    };
  return (
    <div>
         <Countdown title="Countdown" value={deadline} onFinish={onFinish} />
          您没登录，{num}秒后自动跳转至登录页
    </div>
  )
}

export default Islogin(Home)